<template>
<!-- vue3组件中的模板结构可以没有根标签div -->
  <h1>一个人的信息</h1>
  <h2>当前求和为：{{sum}}</h2>
  <button @click="sum++">点我加1</button>
  <hr>
  <h2>当前的信息为：{{msg}}</h2>
  <button @click="msg+='!'">修改信息</button>
  <hr>
  <h2>当前点击时鼠标的坐标为x:{{point.x}},y:{{point.y}}</h2>
</template>

<script>
import {ref,reactive} from 'vue'
import usePoint from "../hooks/UsePoint"

export default {
  name: 'App',
//   vue2
//   watch :{
//     //   sum(newValue,oldValue){
//     //       console.log('sum的值变化了',newValue,oldValue);
//     //   }
//     sum:{
//         immediate:true,
//         deep:true,
//         handler(newValue,oldValue){
//           console.log('sum的值变化了',newValue,oldValue);
//       }
//     }
//   },

  setup() {
    // Data
   
      let sum = ref(0)
      let msg = ref('你好啊')
      let person = reactive({
        age:18,
        name:"管",
        job:{
          j1:{
          title:"java"
          }
        }
      }) 
      let point = usePoint()

  // watchEffect(()=>{
  //   const x1 = sum.value
  //   const x2 = person.age
  //   console.log("watck 配置的回调执行了");
  // })

      return {
        sum,
        msg,
        person,
        point
      }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
